package com.bosch.in.rtp1.ept.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.bosch.in.rtp1.ept.constant.SkippedRecipeConstanst;
import com.bosch.in.rtp1.ept.dao.SkpFshRcpConDao;
import com.bosch.in.rtp1.ept.model.dto.SkippedFshRcpCon;
import com.bosch.in.rtp1.ept.util.SQLStatementLoader;

/**
 * Concrete JDBC implementation of SkpFshRcpConDao. 
 * Provide actions for updating/loading on Skipped Finished Recipe Condition table.
 * @author LIV1HC
 *
 */
public class SkpFshRcpConJDBCDao extends GenericDao implements SkpFshRcpConDao{

	/**
	 * Constructor to inject connection
	 * @param con	DB connection
	 */
	public SkpFshRcpConJDBCDao(Connection connection) {
		super(connection);
	}

	@Override
	public SkippedFshRcpCon getSkpFshRcpCon() throws SQLException {
		String queryString = SQLStatementLoader.getSkpFshRcp();
		ResultSet resultSet = executeQuery(queryString,null);
		SkippedFshRcpCon skCon = new SkippedFshRcpCon();
		if (resultSet.next())
		{
			skCon.setBaseLeadTimeOp(resultSet.getInt(SkippedRecipeConstanst.BASE_LEAD_TIME_OP));
			skCon.setBaseLeadTimeVal(resultSet.getFloat(SkippedRecipeConstanst.BASE_LEAD_TIME_VAL));
			skCon.setRunTimeOp(resultSet.getInt(SkippedRecipeConstanst.RUN_TIME_OP));
			skCon.setRunTimeVal(resultSet.getFloat(SkippedRecipeConstanst.RUN_TIME_VAL));
			skCon.setWaitTimeOp(resultSet.getInt(SkippedRecipeConstanst.WAIT_TIME_OP));
			skCon.setWaitTimeVal(resultSet.getFloat(SkippedRecipeConstanst.WAIT_TIME_VAL));
			skCon.setLastModified(resultSet.getTimestamp(SkippedRecipeConstanst.LAST_MODIFIED).toLocaleString());
		}
		
		// close statement, result set
		resultSet.close();
		close();
		return skCon;
	}

	@Override
	public boolean updateSkpFshRcpCon(SkippedFshRcpCon oldSkippedFshRcpCon, SkippedFshRcpCon newSkippedFshRcpCon) 
			{
		
//		String queryString = SQLStatementLoader.getSkpFshRcpUpd();
//		Object params[] = new Object[12];
//		params[0] = newSkippedFshRcpCon.getBaseLeadTimeVal();
//		params[1] = newSkippedFshRcpCon.getBaseLeadTimeOp();
//		params[2] = newSkippedFshRcpCon.getRunTimeVal();
//		params[3] = newSkippedFshRcpCon.getRunTimeOp();
//		params[4] = newSkippedFshRcpCon.getWaitTimeVal();
//		params[5] = newSkippedFshRcpCon.getWaitTimeOp();
//		params[6] = oldSkippedFshRcpCon.getBaseLeadTimeVal();
//		params[7] = oldSkippedFshRcpCon.getBaseLeadTimeOp();
//		params[8] = oldSkippedFshRcpCon.getRunTimeVal();
//		params[9] = oldSkippedFshRcpCon.getRunTimeOp();
//		params[10] = oldSkippedFshRcpCon.getWaitTimeVal();
//		params[11] = oldSkippedFshRcpCon.getWaitTimeOp();
//		
//		return executeUpdate(queryString, params);
		return true;
	}

	@Override
	public boolean insertSkpFshRcpCon(SkippedFshRcpCon skippedFshRcpCon) throws SQLException
			{
		String queryString = SQLStatementLoader.getSkpFshRcpInst();
		return executeUpdate(queryString, skippedFshRcpCon.getParameterValues().toArray());
	}

	@Override
	public boolean updateSkpCol() throws SQLException {
		String queryString = SQLStatementLoader.getFshRcpSkpColUpd();
		executeQuery(queryString, null);
		return true;
	}

}
